<!--
    group: 发票业务
    name: 发票详情公共组件
-->
<template>
  <div v-if="detailsData">
    <detail-list title=" " :col="2" class="detail-layout">
      <detail-list-item term="发票类型：">
        <span v-if='detailsData.taxType' :class="detailsData.taxType === 1 ? 'd' : 'c'" style="margin-right: 5px">
          {{{1:'专票',2:'普票'}[detailsData.taxType] || ''}}
        </span>
        <!-- 开票类型 1-传统票 2-数电票 3-混合票  -->
        <template v-if="detailsData.ticketType == 1">
          <span v-if='detailsData.taxMedium' :class="detailsData.taxMedium === 1 ? 'a' : 'b'">
            {{{1:'纸质',2:'电子'}[detailsData.taxMedium] || ''}}
          </span>
          <span v-if="detailsData.taxMedium === 2 && detailsData.imageType" class="doc" style="margin-left: 5px;">
            {{ detailsData.imageType }}
          </span>
          <span v-if="detailsData.useSignature == true" style="margin-left: 5px;">使用电子签章</span>
        </template>
        <span v-if="detailsData.ticketType == 2" class="g">数电发票</span>
      </detail-list-item>
      <detail-list-item term="发票金额：">
        {{ detailsData.amount ? detailsData.amount : 0 }}元
        <span v-if="detailsData.returnAmountTotal && invoiceType == '开票'" class="red">（作废/冲红{{ detailsData.returnAmountTotal }}元）</span>
        <span v-if="detailsData.returnAmount && invoiceType == '退票'" class="red">（本次作废/冲红：{{ detailsData.returnAmount }}元）</span>
      </detail-list-item>
    </detail-list>
    <a-divider />

    <template v-if="detailsData.bizStatusShow">
      <detail-list title="发票费用信息" :col="2" class="detail-layout">
        <!-- 当前发票费用 -->
        <table border="1" class="table">
          <tr>
            <th class="center w200">当前发票费用</th>
            <th class="center bg w200">预缴个人经营所得税</th>
            <th class="center bg w200">应缴增值税</th>
            <th class="center bg w200">附加税(增值税*比例)</th>
            <th class="center bg w200">各项税费合计</th>
            <th class="center bg w200">开票服务费</th>
            <th class="center bg w200">本次开票费用合计</th>
          </tr>
          <tr>
            <td class="center bg">费率/税率</td>
            <td class="center">{{ detailsData.personalTaxRate ? detailsData.personalTaxRate + '%' : ''  }}</td>
            <td class="center">{{ detailsData.vatRate ? detailsData.vatRate + '%' : ''  }}</td>
            <td class="center">{{ detailsData.additionalTaxRate ? detailsData.additionalTaxRate + '%' : ''  }}</td>
            <td class="center zg">   </td>
            <td class="center">
              <span v-if="detailsData.payOrder && detailsData.payOrder == -2">线下历史数据</span>
              <span v-else>
                {{ detailsData.serviceChargeRate ? detailsData.serviceChargeRate + '%' : ''  }}
              </span>
            </td>
            <td class="center zg">   </td>
          </tr>
          <tr>
            <td class="center bg">金额</td>
            <td class="center">{{ detailsData.personalTaxMoney ? detailsData.personalTaxMoney : 0  }}元</td>
            <td class="center">{{ detailsData.vatMoney ? detailsData.vatMoney : 0  }}元</td>
            <td class="center">{{ detailsData.additionalTaxMoney ? detailsData.additionalTaxMoney : 0  }}元</td>
            <td class="center">{{ detailsData.taxesTotal ? detailsData.taxesTotal : 0  }}元</td>
            <td class="center">
              <span v-if="detailsData.payOrder && detailsData.payOrder == -2">线下历史数据</span>
              <span v-else>
                {{ detailsData.serviceChargeMoney ? detailsData.serviceChargeMoney : 0 }}元
              </span>
            </td>
            <td class="center">{{ detailsData.total ? detailsData.total : 0  }}元</td>
          </tr>
        </table>
      </detail-list>

      <template v-if="balanceShow">
        <a-divider />
        <detail-list title="发票结算信息" :col="2" class="detail-layout">
          <!-- 同批次费用 -->
          <div v-if="currentlyData.length > 0">
            <h4>同批次开票费用</h4>
            <a-table
              bordered
              :loading="currentlyLoading"
              :columns="currentlyColumns"
              :data-source="currentlyData"
              :scroll="{y: 300}"
              :pagination="false"
            >
              <!--发票类型 1-专票 2-普票-->
              <span slot="taxType" slot-scope="text,record">
                  <span v-if="text" :class="text === 1 ? 'd' : 'c'" style="margin-right: 5px">
                    {{{1:'专票',2:'普票'}[text] || ''}}
                  </span>
                </span>

              <template slot="footer" slot-scope="currentPageData">
                合计： <span style="float: right;">{{ notCost.chargeInfoTotal }}元</span>
              </template>

            </a-table>
          </div>

          <!-- 历史受影响费用 -->
          <div v-if="historyData.length > 0">
            <h4 class="mTop">历史受影响费用</h4>
            <a-table
              bordered
              :loading="currentlyLoading"
              :columns="historyColumns"
              :data-source="historyData"
              :scroll="{x: 400,y: 300}"
              :pagination="false"
            >
              <!-- 发票类型 1-专票 2-普票 -->
              <span slot="taxType" slot-scope="text,record">
                  <span v-if="text" :class="text === 1 ? 'd' : 'c'" style="margin-right: 5px">
                    {{{1:'专票',2:'普票'}[text] || ''}}
                  </span>
                </span>

            </a-table>
          </div>
          <div v-if="currentlyData.length > 0 || historyData.length > 0">
            <div class="flex">
              预计应缴费用合计：
              <span class="orange">{{ notCost.allTotal }}元</span>
            </div>
            <p class="red tips">减免费用将在您完成本次订单支付后，原路退回您的支付账户中！</p>
          </div>
        </detail-list>

        <!-- 发票变动记录  -->
        <detail-list title="发票变动记录" :col="2" class="detail-layout">
          <div v-if="changeData.length > 0">
            <a-table
              bordered size="small"
              :columns="changeColumns"
              :data-source="changeData"
              :scroll="{x: 400,y: 300}"
              :pagination="false"
            >
              <!-- 发票类型 1-专票 2-普票 -->
              <span slot="taxType" slot-scope="text,record">
                <span v-if="text" :class="text === 1 ? 'd' : 'c'" style="margin-right: 5px">
                  {{{1:'专票',2:'普票'}[text] || ''}}
                </span>
              </span>
              <!-- 开票服务费税率 -->
              <span slot="serviceChargeRate" slot-scope="text,record">
                <span v-if="record.payOrder && record.payOrder == -2">线下历史数据</span>
                <span v-else>{{ text ? scalerSign(text) + '%' : '-'  }}</span>
              </span>
              <!-- 开票服务费金额 -->
              <span slot="serviceChargeMoney" slot-scope="text,record">
                <span v-if="record.payOrder && record.payOrder == -2">线下历史数据</span>
                <span v-else>
                  {{ funServe(record.type,record.serviceChargeMoney,record.serviceChargeMoneyDiff) }}
                </span>
              </span>

              <!-- 预缴个人经营所得税金额 -->
              <span slot="personalTaxMoney" slot-scope="text,record">
                {{ funServe(record.type,record.personalTaxMoney,record.personalTaxMoneyDiff) }}
              </span>
              <!-- 应缴增值税金额 -->
              <span slot="vatMoney" slot-scope="text,record">
                {{ funServe(record.type,record.vatMoney,record.vatMoneyDiff) }}
              </span>
              <!-- 附加税金额 -->
              <span slot="additionalTaxMoney" slot-scope="text,record">
                {{ funServe(record.type,record.additionalTaxMoney,record.additionalTaxMoneyDiff) }}
              </span>

            </a-table>
          </div>
        </detail-list>

      </template>
      <a-button @click="seeBalanceInformation" class="mTop" type="primary" style="float:right;margin-bottom: 15px;">
        {{balanceShow ? '收起结算信息' : '查看结算信息'}}
      </a-button>

      <a-divider />
    </template>

    <detail-list title="购买方信息" :col="2" class="detail-layout">
      <detail-list-item term="企业名称：">{{ detailsData.entName }}</detail-list-item>
      <detail-list-item term="税号：">{{ detailsData.entCreditCode }}</detail-list-item>
      <detail-list-item term="公司地址：">{{ detailsData.entAddress }}</detail-list-item>
      <detail-list-item term="电话：">{{ detailsData.entPhone }}</detail-list-item>
    </detail-list>
    <detail-list :col="2" class="detail-layout">
      <detail-list-item term="开户行：">{{ detailsData.entBankName }}</detail-list-item>
      <detail-list-item term="账号：">{{ detailsData.entBankAccount }}</detail-list-item>
    </detail-list>
    <a-divider />

    <detail-list title="开票内容" :col="2" class="detail-layout"></detail-list>
    <div v-for="item in detailsData.taxContents">
      <detail-list :col="2" class="detail-layout">
        <detail-list-item term="发票内容：">
          {{ item.invoiceTypeName }}
          <div class="red">
            {{ item.ultraLimit == 1 ? '请按照实际经营活动选择开票类目，我司将按您提交的开票类目进行赋码开具发票，如税收编码与实际服务场景不匹配，可能会触发发票开具风险预警，请确保一致。' : '' }}
          </div>
        </detail-list-item>
        <detail-list-item term="金额：">{{ item.money }}元</detail-list-item>
      </detail-list>
      <detail-list :col="2" class="detail-layout">
        <detail-list-item term="规格：">{{ item.spec }}</detail-list-item>
        <detail-list-item term="单位：">{{ item.unit }}</detail-list-item>
      </detail-list>
      <detail-list :col="2" class="detail-layout">
        <detail-list-item term="数量：">{{ item.num }}</detail-list-item>
        <detail-list-item term="单价：">{{ item.unitPrice ? item.unitPrice + '元' : '' }}</detail-list-item>
      </detail-list>
    </div>
    <a-divider />

    <detail-list title="销售方信息" :col="2" class="detail-layout">
      <detail-list-item term="企业名称：">{{ detailsData.taxTitle }}</detail-list-item>
      <detail-list-item term="税号：">{{ detailsData.taxCreditCode }}</detail-list-item>
      <detail-list-item term="公司地址：">{{ detailsData.taxAddress }}</detail-list-item>
      <detail-list-item term="电话：">{{ detailsData.taxPhone }}</detail-list-item>
    </detail-list>
    <detail-list :col="2" class="detail-layout">
      <detail-list-item term="开户行：">{{ detailsData.taxBankName }}</detail-list-item>
      <detail-list-item term="账号：">{{ detailsData.taxBankAccount }}</detail-list-item>
    </detail-list>
    <a-divider />

    <detail-list title="票面信息" :col="2" class="detail-layout">
      <detail-list-item term="收款人：">{{ detailsData.collectionUser }}</detail-list-item>
      <detail-list-item term="复核人：">{{ detailsData.reviewUser }}</detail-list-item>
      <detail-list-item term="开票人：">
        {{ detailsData.invoiceUser ? detailsData.invoiceUser
          : {1:'法人开票',2:'代办开票'}[detailsData.invoiceUserType]
        }}
      </detail-list-item>
      <detail-list-item term="票面备注：">{{ detailsData.entRemark }}</detail-list-item>
    </detail-list>
    <a-divider />

    <detail-list title="业务说明" :col="1" class="detail-layout">
      <detail-list-item term="业务结算周期：">
        {{ detailsData.bizSettleAccountsCycleStart }} —
        {{ detailsData.bizSettleAccountsCycleEnd }}
      </detail-list-item>
      <detail-list-item term="服务内容：">{{ detailsData.serviceContent }}</detail-list-item>
      <detail-list-item term="需完成的项目：">{{ detailsData.project }}</detail-list-item>
      <detail-list-item term="验收标准：">{{ detailsData.acceptanceCriteria }}</detail-list-item>
      <detail-list-item term="完成情况：">{{ detailsData.completionStatus }}</detail-list-item>
      <detail-list-item term="结算数据说明：">{{ detailsData.dataDesc }}</detail-list-item>
      <detail-list-item term="开票凭证：">
        <template v-for="item in receiptColorList">
          <!--开票凭证  receiptStatus 1 未上传 2 待审核 3 审核通过 4 审核拒绝-->
          <span v-if="detailsData.receiptStatus == item.key">
            <a-icon :key="item.key" :type="item.type" theme="twoTone" :two-tone-color="item.colorType" />
            <span :style="'margin-left: 5px;color:' + item.colorType">{{ item.verifyDesc }}</span>
          </span>
        </template>
        <span v-if="detailsData.receiptStatus == 4" style="margin-left: 10px;">
          拒绝原因：{{ detailsData.receiptCause ? detailsData.receiptCause : '-' }}
        </span>
        <span v-if="detailsData.certificate && detailsData.certificate.length > 0">
          <a :vhas="vhas[1]" :href="detailsData.certificate[0].fileUrl" class="mLeft" style="text-decoration: underline;">点击查看流水回单</a>
        </span>
        <!-- 未上传状态支持上传流水回单 -->
        <div v-if="(invoiceType == '开票' || invoiceType == '重开票') && (detailsData.receiptStatus == 1 || detailsData.receiptStatus == 4)">
          <p-UpLoadFile
            ref="qyfzrxx_sign"
            :showHelp="true"
            :vhas="vhas[0]"
            v-model="form.url"
            :config="signConfig"
            :customRequestEvent="PUpLoadFileCustomRequestEvent"
          ></p-UpLoadFile>
          <a-button v-has="vhas[0]" class="mLeft" type="primary" @click="saveFlowReceipt">保存</a-button>
        </div>
      </detail-list-item>
      <detail-list-item term="业务说明书：" v-if="detailsData.bizStatus >= 105">
        <!--100: '未提交草稿',101:'待支付',102:'审核中',103:'审核驳回',104:'待核验',105:'待支付',106:'开票中',107:'待确认寄送',108:'待寄送',109:'已寄送',110:'已完成',111:'待确认重开',112:'确认重开',113:'待确认退票',114:'确认退票',116:'有退款',-->
        <span style="visibility: hidden">业务说明书</span>
        <p-ImgGroup :vhas="vhas[2]" :value="defaultFileList" :showHelp="true" />
      </detail-list-item>
      <detail-list-item term="合同及补充材料：">
        <span style="visibility: hidden">合同及补充材料</span>
        <div v-if="supplementFileList && supplementFileList.length > 0">
          <p-ImgGroup :vhas="vhas[3]" :value="supplementFileList" :showHelp="true" />
        </div>
        <span v-else>
          <a-icon type="info-circle" theme="twoTone" two-tone-color="#bbb" />
          <span :style="'margin-left: 5px;color:#bbb'">未上传</span>
        </span>
      </detail-list-item>
    </detail-list>
    <a-divider />

    <template v-if="detailsData.ticketType == 2">
      <detail-list title="发票交付方式" :col="1" class="detail-layout">
        <detail-list-item term="交付方式：">
          {{{1:'邮箱交付',2:'二维码交付',3:'线下交付',4:'勤税宝交付'}[detailsData.deliveryMethod] || ''}}
          <span class="mLeft">
            <span v-if="detailsData.deliveryMethod == 1">{{ detailsData.email }}</span>
            <span v-if="detailsData.deliveryMethod == 3 || detailsData.deliveryMethod == 4">
              {{{1:'下载为PDF',2:'下载为OFD',3:'下载为XML'}[detailsData.deliveryContent] || ''}}
            </span>
          </span>
        </detail-list-item>
      </detail-list>
      <a-divider />
    </template>

    <template v-if="detailsData.ticketType == 1">
      <detail-list title="发票邮寄信息" :col="1" class="detail-layout">
        <template v-if="detailsData.taxMedium == 1">
          <detail-list-item term="收件人：">{{ detailsData.invcMailReq ? detailsData.invcMailReq.mailUserName : '' }}</detail-list-item>
          <detail-list-item term="手机号码：">{{ detailsData.invcMailReq ? detailsData.invcMailReq.mailUserPhone : '' }}</detail-list-item>
          <detail-list-item term="收件地址：">{{ detailsData.invcMailReq ? detailsData.invcMailReq.mailUserAddress : '' }}</detail-list-item>
        </template>
        <template v-if="detailsData.taxMedium == 2">
          <detail-list-item term="收件邮箱：">{{ detailsData.invcMailReq ? detailsData.invcMailReq.email : '' }}</detail-list-item>
        </template>
      </detail-list>
      <a-divider />
    </template>

    <detail-list title="发票开具说明" :col="1" class="detail-layout">
      <detail-list-item v-if="detailsData.ticketType == 1" term="开票张数：">{{ detailsData.billUseNum }}张</detail-list-item>
      <detail-list-item term="发票开具说明：">{{ detailsData.taxRemark }}</detail-list-item>
    </detail-list>
    <a-divider />

  </div>
</template>

<script>
import { findPayOrderRecord, turnFlowReceipt, findPayOrderChangeRecord } from '@/api/invoiceAdminister'
import { conversionElement, cloneObject,percentConversion } from '@/utils/util'
import DetailList from '@/components/tools/DetailList'
const DetailListItem = DetailList.Item
export default {
  name: 'invoiceCommonDetails',
  components: {
    DetailList,
    DetailListItem
  },
  props: ['detailsData', 'invoiceType','vhas'],
  data(){
    return{
      //上传流水回单
      form: {
        fileList: []
      },
      signConfig: {
        // 此参数必填  上传路径
        dir: '/qsb/invoice/',
        // 此参数必填 表示要采用什么模式   可选的值： 单文件  多文件  身份证  all  ；  单文件 对应 card1 ；   多文件 对应  card3 ； 身份证  对应  card1（身份证正面）、card2（身份证反面）
        model: '单文件',
        required: true,
        // 此参数选填   要回显的数据 card1 card2 的值的格式为：{name:'',url:''} ;  card3 的值的格式为 [{name:'',url:''}，{name:'',url:''}]
        defaultFileList: {
          card1: {},
        },
        tips: {
          card1: "上传流水回单",
        },
        // 此参数集必填
        fielConfig: {
          // 允许上传的文件类型 当为空时表示不限制  默认为空
          //    可供选择类型：
          //          图片('jpg', 'png', 'jpeg')
          //          文档('xlsx', 'xls', 'pptx', 'ppt', 'pdf', 'doc', 'docx', 'txt')
          //          压缩包('zip', 'rar')  发票('pdf', 'jpg', 'png', 'jpeg', 'doc', 'docx', 'zip', 'rar')
          //          PDF(pdf)
          //          委托代征协议('pdf','jpg', 'png', 'jpeg')
          //          我的任务('jpg', 'png', 'jpeg','pdf','xlsx', 'xls', 'pdf', 'doc', 'docx','zip', 'rar' )
          // eg:
          //    当值为string类型时，对所有（card1,card2,card3）的有效；
          //    当值为对象（{"card1":'图片',"card2":'文档', "card3":'PDF'}）时，可指定每个（card1/card2/card3）所对应的类型
          type: '发票',
          // 允许上传的文件个数  默认值为1
          // eg: 1 表示只允许上传1个文件；
          //      当值为对象（{"card1":1,"card2":2, "card3":3}）时，可指定每个（card1/card2/card3）所对应的类型
          size: 1,
          // 上传的单个文件大小 单位为 MB  默认值为1
          //  eg: 当值为 number 时，对所有（card1,card2,card3）的有效；当值为对象（{"pdf":5,"xlsx":10, "zip":100}）时,可指定对应的文件类型的大小（单位：MB）
          singleFileSize: 10
        }
      },
      //业务说明书
      receiptColorList: [
        {
          key: 4,
          type: 'close-circle',
          colorType: '#ff2b2b',
          verifyDesc: '审核拒绝'
        },
        {
          key: 3,
          type: 'check-circle',
          colorType: '#52c41a',
          verifyDesc: '审核通过'
        },
        {
          key: 2,
          type: 'clock-circle',
          colorType: '#ffac56',
          verifyDesc: '待审核'
        },
        {
          key: 1,
          type: 'info-circle',
          colorType: '#bbb',
          verifyDesc: '未上传'
        }
      ],
      defaultFileList: [],
      //合同及补充材料
      supplementFileList: [],


      //发票详情费用结算信息
      balanceShow: false,   //用于判断不展示费用信息的展示
      statusList: [101,100,102,103,104,117,118],
      notCost: {},  //金额对象
      //本次费用
      currentlyLoading: false,
      currentlyData: [],
      currentlyColumns: [
        {
          title: '购买方',
          dataIndex: 'entName',
          width: 150,
          align: 'center'
        },
        {
          title: '发票类型',
          dataIndex: 'taxType',
          width: 100,
          scopedSlots: {customRender: 'taxType'},
          align: 'center'
        },
        {
          title: '开票金额',
          dataIndex: 'amount',
          customRender: (text,record) => {
            if (text != null){
              return Math.round(text * 100)/10000 + '元'
            }else {
              return '-'
            }
          },
          width: 120,
          align: 'center'
        },
        {
          title: '应缴个税',
          dataIndex: 'personalTaxMoney',
          customRender: (text,record) => {
            if (text != null){
              return Math.round(text * 100)/10000 + '元'
            }else {
              return '-'
            }
          },
          width: 100,
          align: 'center'
        },
        {
          title: '应缴增值税',
          dataIndex: 'vatMoney',
          customRender: (text,record) => {
            if (text != null){
              return Math.round(text * 100)/10000 + '元'
            }else {
              return '-'
            }
          },
          width: 100,
          align: 'center'
        },
        {
          title: '应缴附加税',
          dataIndex: 'additionalTaxMoney',
          customRender: (text,record) => {
            if (text != null){
              return Math.round(text * 100)/10000 + '元'
            }else {
              return '-'
            }
          },
          width: 100,
          align: 'center'
        },
        {
          title: '开票服务费',
          dataIndex: 'serviceChargeMoney',
          customRender: (text,record) => {
            if (text != null){
              return Math.round(text * 100)/10000 + '元'
            }else {
              return '-'
            }
          },
          width: 100,
          align: 'center'
        },
      ],
      //历史费用
      historyData: [],
      historyColumns: [
        {
          title: ' ',
          dataIndex: 'invoiceName',
          width: 70,
          align: 'center'
        },
        {
          title: '发票类型',
          dataIndex: 'taxType',
          width: 100,
          scopedSlots: {customRender: 'taxType'},
          align: 'center'
        },
        {
          title: '开票金额',
          dataIndex: 'amount',
          customRender: (text,record) => {
            if (text != null){
              return Math.round(text * 100)/10000 + '元'
            }else {
              return '-'
            }
          },
          width: 120,
          align: 'center'
        },
        // {
        //   title: '应缴个税',
        //   dataIndex: 'personalTaxMoney',
        //   customRender: (text,record) => {
        //     if (text != null){
        //       return Math.round(text * 100)/10000 + '元'
        //     }else {
        //       return '-'
        //     }
        //   },
        //   width: 120,
        //   align: 'center'
        // },
        {
          title: '个税差额',
          dataIndex: 'personalTaxMoneyDiff',
          customRender: (text,record) => {
            if (text != null){
              return Math.round(text * 100)/10000 + '元'
            }else {
              return '-'
            }
          },
          width: 120,
          align: 'center'
        },
        {
          title: '应缴增值税',
          dataIndex: 'vatMoney',
          customRender: (text,record) => {
            if (text != null){
              return Math.round(text * 100)/10000 + '元'
            }else {
              return '-'
            }
          },
          width: 120,
          align: 'center'
        },
        {
          title: '增值税差额',
          dataIndex: 'vatMoneyDiff',
          customRender: (text,record) => {
            if (text != null){
              return Math.round(text * 100)/10000 + '元'
            }else {
              return '-'
            }
          },
          width: 120,
          align: 'center'
        },
        {
          title: '应缴附加税',
          dataIndex: 'additionalTaxMoney',
          customRender: (text,record) => {
            if (text != null){
              return Math.round(text * 100)/10000 + '元'
            }else {
              return '-'
            }
          },
          width: 120,
          align: 'center'
        },
        {
          title: '附加税差额',
          dataIndex: 'additionalTaxMoneyDiff',
          customRender: (text,record) => {
            if (text != null){
              return Math.round(text * 100)/10000 + '元'
            }else {
              return '-'
            }
          },
          width: 120,
          align: 'center'
        },
        {
          title: '开票服务费',
          dataIndex: 'serviceChargeMoney',
          customRender: (text,record) => {
            if (text != null){
              return Math.round(text * 100)/10000 + '元'
            }else {
              return '-'
            }
          },
          width: 120,
          align: 'center'
        },
        {
          title: '服务费差额',
          dataIndex: 'serviceChargeMoneyDiff',
          customRender: (text,record) => {
            if (text != null){
              return Math.round(text * 100)/10000 + '元'
            }else {
              return '-'
            }
          },
          width: 120,
          align: 'center'
        },
      ],
      //变动记录
      changeData: [],  //变动记录
      changeColumns: [
        {
          title: '发票类型',
          dataIndex: 'taxType',
          key: 'taxType',
          width: 100,
          scopedSlots: {customRender: 'taxType'},
          align: 'center'
        },
        {
          title: '预缴个人经营所得税税率',
          dataIndex: 'personalTaxRate',
          key: 'personalTaxRate',
          width: 210,
          customRender: (text,record) => {
            if (text){
              return Math.round(text * 10000) / 100 + '%'
            }else {
              return '-'
            }
          },
          align: 'center'
        },
        {
          title: '应缴增值税税率',
          dataIndex: 'vatRate',
          key: 'vatRate',
          width: 150,
          customRender: (text,record) => {
            if (text){
              return Math.round(text * 10000) / 100 + '%'
            }else {
              return '-'
            }
          },
          align: 'center'
        },
        {
          title: '附加税税率',
          dataIndex: 'additionalTaxRate',
          key: 'additionalTaxRate',
          width: 150,
          customRender: (text,record) => {
            if (text){
              return Math.round(text * 10000) / 100 + '%'
            }else {
              return '-'
            }
          },
          align: 'center'
        },
        {
          title: '服务费税率',
          dataIndex: 'serviceChargeRate',
          key: 'serviceChargeRate',
          width: 130,
          scopedSlots: {customRender: 'serviceChargeRate'},
          align: 'center'
        },
        {
          title: '服务费金额',
          dataIndex: 'serviceChargeMoney',
          key: 'serviceChargeMoney',
          scopedSlots: {customRender: 'serviceChargeMoney'},
          width: 130,
          align: 'center'
        },
        {
          title: '预缴个人经营所得税金额',
          dataIndex: 'personalTaxMoney',
          key: 'personalTaxMoney',
          scopedSlots: {customRender: 'personalTaxMoney'},
          width: 210,
          align: 'center'
        },
        {
          title: '应缴增值税金额',
          dataIndex: 'vatMoney',
          key: 'vatMoney',
          scopedSlots: {customRender: 'vatMoney'},
          width: 150,
          align: 'center'
        },
        {
          title: '附加税金额',
          dataIndex: 'additionalTaxMoney',
          key: 'additionalTaxMoney',
          scopedSlots: {customRender: 'additionalTaxMoney'},
          width: 150,
          align: 'center'
        },
        {
          title: '各项税费合计',
          dataIndex: 'taxesTotal',
          key: 'taxesTotal',
          width: 150,
          customRender: (text,record) => {
            if (text != null){
              return Math.round(text * 100)/10000 + '元'
            }else {
              return '-'
            }
          },
          align: 'center'
        },
        {
          title: '本次开票费用合计',
          dataIndex: 'total',
          key: 'total',
          width: 160,
          customRender: (text,record) => {
            if (text != null){
              return Math.round(text * 100)/10000 + '元'
            }else {
              return '-'
            }
          },
          align: 'center'
        },
      ],   //变动记录title
    }
  },
  watch:{
    detailsData:{
      handler(val){
        //业务说明书文件回显
        if (val.bizSettleAccountsUrl){
          this.defaultFileList = [{
              title: '业务说明书',
              url: val.bizSettleAccountsUrl,
              isShowWatermark: false
          }]
        }
        //合同及补充材料回显
        if (val.replenishMaterial && val.replenishMaterial.length > 0){
          let arryNew = [];
          val.replenishMaterial.map((item, index) => {
            arryNew.push(Object.assign({}, item, { name: item.fileName, url: item.fileUrl }));
            return arryNew;
          });
          this.supplementFileList = arryNew;
        }

        //处理发票费用信息
        if (val && val.payOrder){
          let data = cloneObject(val);

          this.detailsData.personalTaxMoney = conversionElement(data.personalTaxMoney);  //个人经营所得税
          this.detailsData.vatMoney = conversionElement(data.vatMoney);  //增值税
          this.detailsData.additionalTaxMoney = conversionElement(data.additionalTaxMoney);  //附加税

          this.detailsData.taxesTotal = conversionElement(data.taxesTotal);  //各项税费合计
          this.detailsData.total = conversionElement(data.total);  //本次开票费用合计

          this.detailsData.personalTaxRate = percentConversion(data.personalTaxRate);  //个人经营所得税税率
          this.detailsData.vatRate = percentConversion(data.vatRate);  //增值税税率
          this.detailsData.additionalTaxRate = percentConversion(data.additionalTaxRate);  //附加税税率
          //判断是否为迁移数据
          if (val.payOrder == -2){
            this.detailsData.serviceChargeMoney = '线下历史数据'; //服务费
            this.detailsData.serviceChargeRate = '线下历史数据';  //服务费税率
          }else {
            this.detailsData.serviceChargeMoney = conversionElement(data.serviceChargeMoney); //预估服务费
            this.detailsData.serviceChargeRate = percentConversion(data.serviceChargeRate);  //服务费税率
          }

          //判断不展示费用信息的展示(该票不含失败标识&&支付以前状态不展示)
          const bizStatusShow = this.statusList.includes(val.bizStatus); //true_含 false_不含
          if (data.errorFlag <= 1 && bizStatusShow){
            this.detailsData.bizStatusShow = false;
          }else {
            this.detailsData.bizStatusShow = true;
            this.invoicePayChangeRecord(data.serialNum);  //变动记录

            //获取结算信息
            if (this.invoiceType == '退票'){
              this.estimatedCost(data.taxPayOrder);  //结算信息
            }else{
              this.estimatedCost(data.payOrder);
            }
          }

        }
      }
    }
  },
  methods:{
    //查看结算信息
    seeBalanceInformation(){
      this.balanceShow = !this.balanceShow;
    },
    //  ---------------------------- 上传流水回单 ↓ -----------------------
    //上传保存流水回单
    saveFlowReceipt() {
      const check_lshd_sfrz = this.$refs['qyfzrxx_sign'].getDataCheckRes({card1:'请上传流水回单'})
      if (check_lshd_sfrz.card1===true) {
        this.form.fileList = [
          {
            fileName: this.form.url.card1.name,
            fileUrl: this.form.url.card1.url
          }
        ]
      } else {
        this.$message.warning('请检查流水回单是否上传');
        return false
      }
      //请求上传流水回单接口
      let params = {}
      params.entId = this.detailsData.entId //企业ID
      params.fileList = this.form.fileList //流水回单附件
      params.invcId = this.detailsData.id //发票ID
      params.serialNum = this.detailsData.serialNum //发票流水号

      turnFlowReceipt(params).then(res => {
        if (res.success) {
          this.$message.success('流水回单上传成功');
          this.getListDetails(this.id);  //重新刷新详情
        } else {
          this.$message.warning(res.message);
        }
      })
    },
    //  ---------------------------- 获取结算信息 ↓ -----------------------
    //获取结算信息
    estimatedCost(payOrder){
      this.currentlyLoading = true;
      findPayOrderRecord(payOrder).then(res => {
        if (res.success) {
          if (res.result){
            this.currentlyLoading = false;
            let data = cloneObject(res.result.entChargeInfoVOS[0]);

            //处理发票金额
            this.notCost.allTotal = conversionElement(data.allTotal) || 0;  //预计应缴费用
            this.notCost.chargeInfoTotal = conversionElement(data.chargeInfoTotal) || 0;  //本次费用合计

            this.currentlyData = data.chargeInfoList || [];  //本次费用列表
            //历史费用列表
            if (data.chargeInfoDiffList.length > 0 && data.chargeInfoDiffTotal){
              let arrList = data.chargeInfoDiffList || [];
              this.historyData = arrList;
              this.notCost.additionalTaxMoneyDiff = conversionElement(data.chargeInfoDiffTotal.additionalTaxMoneyDiff);  //应缴增值税附加税总和
              this.notCost.serviceChargeMoneyDiff = conversionElement(data.chargeInfoDiffTotal.serviceChargeMoneyDiff);  //减免个税服务费总和
              this.notCost.newDiffTotal = Math.abs(this.notCost.serviceChargeMoneyDiff);  //减免费用
            }else {
              this.historyData = [];
            }
          }
        } else {
          this.$message.warning(res.message);
        }
      })
    },
    //获取发票金额变动记录
    invoicePayChangeRecord(serialNum){
      let params = {};
      params.serialNum = serialNum;
      findPayOrderChangeRecord(params).then(res => {
        if (res.success) {
          if (res.result){
            let data = cloneObject(res.result.entChargeInfoVOS[0]);
            //变动信息记录
            let arr1 = data.chargeInfoList || [];  //初次费用列表
            let arr2 = data.chargeInfoDiffList || [];  //历史金额变动列表

            this.changeData = [...arr1, ...arr2];  //变动列表

          }
        } else {
          this.$message.warning(res.message);
        }
      })
    },
    //判断使用那个值
    funServe(type,oldVal,newVal){
      let val;
      if (type == 2){
        val = conversionElement(newVal);
      }else{
        val = conversionElement(oldVal);
      }

      if (val){
        return val + '元';
      }else {
        return '-'
      }
    },
    //分转元
    scalerPrice(money){
      return conversionElement(money);
    },
    //百分比转换    0.6 => 60%
    scalerSign(num){
      return percentConversion(num);
    }
  }
}
</script>

<style scoped lang="less">
//表格
.table{
  width: 100%;
  border: 1px solid #e8e8e8;
}
.center{text-align: center;padding: 8px 16px;}
.bg{background: #fafafa;}
.zg{background: #E5E5E5;}
.w200{width:200px;}


//费用信息
.mTop{
  margin-top: 30px;
}
.flex{
  margin-top: 10px;
  display: flex;
  justify-content: space-between;
}
.tips{
  margin-top: 15px;
  font-size: 12px;
  text-align: right;
}

</style>
